package com.itheima.网络编程.tcp编程.tcp编程.TCP;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
import java.util.UUID;

public class 文件上传服务端一 {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        ServerSocket ss = new ServerSocket(10001);
        while (true) {
            Socket sk = ss.accept();
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("day16 网络编程\\" + UUID.randomUUID().toString() + ".png"));
            BufferedInputStream bis = new BufferedInputStream(sk.getInputStream());
            byte[] bys = new byte[1024];
            int len;
            while ((len = bis.read(bys)) != -1) {
                bos.write(bys, 0, len);
                bos.flush();
            }
            System.out.println("========================");
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(sk.getOutputStream()));
            System.out.println("服务器反馈:");
            String str = sc.next();
            bw.write(str);
            bw.close();
            sk.close();
            bos.close();
            bis.close();

        }
        //ss.close();
    }
}
